import React, { Component } from 'react';
import PropTypes from 'prop-types';
import TokenAPI from '../../../api/auth/index';

class ShareLi extends Component {
    componentDidMount(){
        this.getShare().then((res)=>{
            if(res.code === 1){
                window.wx.config({
                    debug:true,
                    appId:'wxbeac869bcc9744a7',
                    timestamp:'1524879721',
                    nonceStr:'2d1de712-70e7-421d-8501-3ee2cfa7c16a',
                    signature:'f0252f7f8da7ab1811eb9145b07d7a4d79272b1b',
                    jsApiList:[
                        'onMenuShareTimeline', //分享给好友
                        'onMenuShareAppMessage', //分享到朋友圈
                    ]
                });

                wx.onMenuShareTimeline({
                    title: "朋友群", // 分享标题
                    link: '', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: '',// 分享图标
                    success: function () {
                        alert('已分享')
                    },
                    cancel: function () {
                        alert('已取消')
                    }
                });

                //分享给朋友
                wx.onMenuShareAppMessage({
                    title: "friends", // 分享标题
                    desc: '好东西分享给你', // 分享描述
                    link: "", // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: "", // 分享图标
                    type: '', // 分享类型,music、video或link，默认为link
                    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                    success: function () {
                        alert('已分享')
                    },
                    cancel: function () {
                        alert('已取消')
                    }
                });

                wx.ready(function(){
                    console.log("ready");
                });

                wx.error(function(res){
                    console.log("error");
                });
            }
        });
    }


    getShare = async () => {
        const url ="http://www.baidu.com";
        const response = await TokenAPI.getDownloadUrl(url);
        const { code, data } = response;
        if (code === 1) {
            return response;
        }
    }

    render() {
        return (
            <div>
            </div>
        );
    }
}
//
// ShareLi.propTypes = {
//     imgList: PropTypes.array.isRequired,
// };

export default ShareLi;
